
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<script  type="text/javascript">
    function show_comfirm()
    {
        var comfirmBox;
        comfirmBox = confirm("Xóa toàn bộ thông tin về giỏ hàng của bạn phải không?");
		
        if(comfirmBox == true){
            window.location = "GioHang.do?Action=XoaGioHang";
        }
        else{
                 
        }
    }
</script>
<form  name="formGioHang" method="get" action="GioHang.do">
    <input hidden="" name="MainContent"  type="text" value="GioHang" />
    <table width="680" border="1" cellspacing="0" cellpadding="0" id="tableformDangNhap">
        <tr>
            <td bgcolor="#FF0000" height="35" colspan="7" class="menu1" style="text-align:center">
                <span style="font-weight: bold">GIỎ HÀNG CỦA BẠN</span>
            </td>
        </tr>
        <tr class="trtenCotGioHang">
            <td align="center" width="5%" >
                STT
            </td>
            <td align="center" width="17%">
                Hình
            </td>
            <td align="left" width="23%" style="text-align:center">
                Tên sản phẩm
            </td>
            <td align="center" width="15%" style="text-align:center">
                Số lượng
            </td>
            <td align="right" width="15%" style="text-align:center">Đơn giá(đ)</td>

            <td colspan="2"  align="center" width="25%" style="text-align:center">Tổng tiền(đ)</td>
        </tr>
        <c:set var="tongtien" value="0"/>
        <c:if test="${sessionScope.GioHang.size() > 0}">
            <c:forEach var="i" begin="0" end="${sessionScope.GioHang.size()-1}" step="1">
                <c:set var="sp" value="${sessionScope.GioHang.get(i)}"/>
                <c:set var="tongtien" value="${tongtien+sessionScope.GioHang.get(i).getDonGia()*sessionScope.GioHang.get(i).getSoLuong()}"/>
                
                <tr>
                    <td align="center">1</td>
                    <td align="center">
                        <a href="index.jsp?MainContent=ChiTietSanPham&MaSanPham=${sp.getMaSanPham()}" title="Click xem chi tiết sản phẩm"><img src="${sp.getHinhAnh()}"  width="80%" height="70" border="0" /></a>
                    </td>
                    <td align="left">
                        <a href="index.jsp?MainContent=ChiTietSanPham&MaSanPham=${sp.getMaSanPham()}" title="Click xem chi tiết sản phẩm" class="sanpham_link">${sp.getTenSanPham()}</a>
                    </td>
                    <td align="center">
                        <script>
                            function tangGiamSoLuong${i}(x, max){							  
                                var slt = document.getElementById("soLuong${i}");
                                var sl = parseInt(slt.value);
                                if(x == 1){if(sl>0){sl = sl - 1;}
                                }else{if(sl<max){sl =sl+1;}}
                                slt.value = sl;							  
                            }
                        </script> 

                        <button type="button" onclick="tangGiamSoLuong${i}(1,20)">-</button>

                        <input name="soLuong" type="number" id="soLuong${i}" value="${sp.getSoLuong()}" size="5" style="width:20px"/>
                        <button type="button" onclick="tangGiamSoLuong${i}(0,20)">+</button>                                 

                    </td>
                    <td align="right"><fmt:formatNumber type="currency" value="${sp.donGia}" /></td>
                    <td align="right"><fmt:formatNumber type="currency" value="${sp.getDonGia() * sp.getSoLuong()}" /></td>
                    <td align="center"><a href="GioHang.do?Action=Xoa&MaSanPham=${sp.getMaSanPham()}" class="sanpham_link">Xóa</a></td>
                </tr>
            </c:forEach>
        </c:if>
        <tr>
            <td align="right" colspan="5" >Thành tiền:</td><td colspan="2" align="center" style="color:#C60">   <fmt:formatNumber type="currency" value="${tongtien}" /></td>
        </tr>
        <tr>
            <td align="right" colspan="5">Phí vận chuyển:</td><td colspan="2" align="center" style="color:#C60">   <fmt:formatNumber type="currency" value="10000" /></td>

        </tr>
        <tr>
            <td align="right" colspan="5">Tổng tiền thanh toán:</td><td colspan="2" align="center" style="color:#C60">   <fmt:formatNumber type="currency" value="${tongtien+10000}" /></td>

        </tr>
        <tr>
            <td colspan="7">
                <table width="100%" border="0">
                    <tr>
                        <td align="center"><a href="TrangChu.do"><input type="button" value="Tiếp tục mua" class="btGioHang"  /></a></td>
                        <td align="center"><input type="button" onclick="show_comfirm()" value="Xóa giỏ hàng" class="btGioHang"  /></td>
                        <td  align='center'><input type='image'  src='images/btCapNhat.png'  name='CapNhat'/></td>

                        <td align="center"><a href="GioHang.do?Action=CheckOut"><input type="button" value="Thanh toán" class="btGioHang"  /></a></td>

                    </tr>
                </table>

            </td>
        </tr>
    </table>

</form>
